###Graphs revision for publication###

# packages, if not installed use "install.packages()"
library(readxl)
library(ggplot2) ## developer version of ggplot2! can be installed from GitHub using package "devtools" and ## devtools::install_github("hadley/ggplot2")
library(gridExtra)
library(grid)
library(ggthemes)
library(scales)
library(gtable)
## loading the data in R

setwd("")

##############Figure1######

## Adding country variable

ttest_econ <- read.csv("ttest_econ_issue.csv")
ttest_isds <- read.csv("ttest_isds_issue.csv")
ttest_stand <- read.csv("ttest_stand_issue.csv")


## Setting up auxiliary objects 

labels <- c("", "Neu   -   Neg", "Neg   -   Neg", "Pos   -   Neg", "Neu   -   Pos", "Neg   -   Pos", "Pos   -   Pos")
aux <- as.numeric(c(0:6))
aux_df <- as.data.frame(cbind(labels, as.numeric(aux)))

## Economic issue 

K1 <- ggplot(ttest_econ, aes(color=factor(country), x = as.numeric(item), y = as.numeric(mean))) +         ## setting up the plot
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) +
  theme_bw() +
  ylim(c(-2.9, 2.9)) +
  coord_flip() + scale_colour_manual(name  ="Country",
                                      labels=c("GER", "USA"),
                                      values=c("black", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="Economic Issue",
       subtitle="Overall, do you personally think that the TTIP \nagreement will have positive or negative \neffects on <<Country's>> economy?"
  )  

##Standards 

K2 <- ggplot(ttest_stand, aes(color = factor(country), x = as.numeric(item), y = as.numeric(mean))) +         ## setting up the plot
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) +
  theme_bw() +
  ylim(c(-2.9, 2.9)) +
  coord_flip() + 
  scale_colour_manual(name  ="Country",
                      labels=c("GER", "USA"),
                      values=c("black", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="Standards",
       subtitle= "Overall, do you personally think that the proposed \nharmonization of safety and quality standards \nwill have positive or negative effects on <<Country>>?"
  )

##ISDS 

K3 <- ggplot(ttest_isds, aes(color = factor(country), x = as.numeric(item), y = as.numeric(mean))) +         ## setting up the plot
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) +
  theme_bw() +
  ylim(c(-2.9, 2.9)) +
  coord_flip() +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(),
    axis.line.x=element_line(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.position="bottom",
    legend.title=element_blank(),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) + 
  scale_colour_manual(name  ="Country",
                      labels=c("GER", "USA"),
                      values=c("black", "grey")) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="ISDS",
       subtitle="Overall, do you personally think that including an investor-state \ndispute settlement mechanism (ISDS) in the TTIP agreement \nwill have positive or negative effects on <<Country>>?"
  ) 


K4 <- ggplot(data = aux_df, aes(1, aux)) + 
  geom_text(label = labels) + 
  ylim(0.03,6.05) +
  xlim(0.99, 1.01) +
  theme_bw() +
  theme(panel.grid.major=element_blank(),
        panel.grid.minor = element_blank(),
        panel.border=element_blank(), 
        axis.text.y=element_blank(), 
        axis.ticks.y=element_blank(), 
        axis.title=element_blank(),
        axis.line.x=element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        plot.title = element_text(size = 11, colour = "black", hjust= .5),
        plot.subtitle = element_text(size = 16, hjust = 1.1, face = "bold")
  ) + 
  labs(title="\n \n \n", subtitle = "Prior - Treatment") 

final <- arrangeGrob(K4, K1, K2, K3, ncol = 4, widths=unit(c(190,350,350,350),"pt")) 
grid.arrange(K4, K1, K2, K3, ncol = 4, widths=unit(c(180,350,350,350),"pt")) 


## exporting

pdf("Figure1.pdf", width = 18, height = 8) # Open a new pdf file
grid.arrange(K4, K1, K2, K3, ncol = 4, widths=unit(c(180,350,350,350),"pt"))  # Write the grid.arrange in the file
dev.off() # Close the file




###FIGURE 2###



## Adding country variable

ttest_ger <- read.csv("ttest_combined_interest_deu_new.csv")
ttest_us <- read.csv("ttest_combined_interest_usa_new.csv")


## Setting up auxiliary objects 

labels <- c("", "Neu   -   Neg", "Neg   -   Neg", "Pos   -   Neg", "Neu   -   Pos", "Neg   -   Pos", "Pos   -   Pos")
aux <- as.numeric(c(0:6))
aux_df <- as.data.frame(cbind(labels, as.numeric(aux)))


## Germany 

K5 <- ggplot(ttest_ger, aes(color=factor(interest), x = as.numeric(item), y = as.numeric(mean))) +
  #geom_pointrange(aes(ymin = ci_low, ymax = ci_up),position = position_dodge(width=.6)) + 
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) +  
  theme_bw() +
  ylim(c(-3.05, 3.05)) +
  coord_flip() + scale_colour_manual(name  ="Interest",
                                       labels=c("High", "Medium", "Low"),
                                       values=c("black", "darkgrey", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="Germany")


## USA 

K6 <- ggplot(ttest_us, aes(color=factor(interest), x = as.numeric(item), y = as.numeric(mean))) +
  #geom_pointrange(aes(ymin = ci_low, ymax = ci_up),position = position_dodge(width=.6)) + 
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) + 
  theme_bw() +
  ylim(c(-3.05, 3.05)) +
  coord_flip() + scale_colour_manual(name  ="Interest",
                                     labels=c("High", "Medium", "Low"),
                                     values=c("black", "darkgrey", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="USA")


## Label 

K7 <- ggplot(data = aux_df, aes(1, aux)) + 
  geom_text(label = labels) + 
  ylim(0.03,6.05) +
  xlim(0.99, 1.01) +
  theme_bw() +
  theme(panel.grid.major=element_blank(),
        panel.grid.minor = element_blank(),
        panel.border=element_blank(), 
        axis.text.y=element_blank(), 
        axis.ticks.y=element_blank(), 
        axis.title=element_blank(),
        axis.line.x=element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        plot.title = element_text(size = 11, colour = "black", hjust= 0.5),
        plot.subtitle = element_text(size = 16, hjust = 1.1, face = "bold")
  ) + 
  labs(title="\n \n \n", subtitle = "Prior - Treatment") 

final <- arrangeGrob(K7, K5, K6, ncol = 3, widths=unit(c(190,350,350),"pt")) 
grid.arrange(K7, K5, K6, ncol = 3, widths=unit(c(180,350,350),"pt")) 


## exporting

pdf("Figure2.pdf", width = 18, height = 8) # Open a new pdf file
grid.arrange(K7, K5, K6, ncol = 3, widths=unit(c(180,350,350),"pt"))  # Write the grid.arrange in the file
dev.off() # Close the file





###Figure 3###


## Adding country variable

ttest_ger <- read.csv("ttest_combined_justification_deu.csv")
ttest_us <- read.csv("ttest_combined_justification_usa.csv")


## Setting up auxiliary objects 

labels <- c("", "Neu   -   Neg", "Neg   -   Neg", "Pos   -   Neg", "Neu   -   Pos", "Neg   -   Pos", "Pos   -   Pos")
aux <- as.numeric(c(0:6))
aux_df <- as.data.frame(cbind(labels, as.numeric(aux)))


## Germany 

K1 <- ggplot(ttest_ger, aes(color=factor(justification), x = as.numeric(item), y = as.numeric(mean))) +
  #geom_pointrange(aes(ymin = ci_low, ymax = ci_up),position = position_dodge(width=.6)) + 
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) +  
  theme_bw() +
  ylim(c(-3, 3)) +
  coord_flip() + scale_colour_manual(name  ="Justification",
                                     labels=c("No justification", "With justification"),
                                     values=c("black", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="Germany")


## USA 

K2 <- ggplot(ttest_us, aes(color=factor(justification), x = as.numeric(item), y = as.numeric(mean))) +
  #geom_pointrange(aes(ymin = ci_low, ymax = ci_up),position = position_dodge(width=.6)) + 
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) + 
  theme_bw() +
  ylim(c(-3, 3)) +
  coord_flip() + scale_colour_manual(name  ="Justification",
                                     labels=c("No justification", "With justification"),
                                     values=c("black", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="USA")


## Label 

K3 <- ggplot(data = aux_df, aes(1, aux)) + 
  geom_text(label = labels) + 
  ylim(0.03,6.05) +
  xlim(0.99, 1.01) +
  theme_bw() +
  theme(panel.grid.major=element_blank(),
        panel.grid.minor = element_blank(),
        panel.border=element_blank(), 
        axis.text.y=element_blank(), 
        axis.ticks.y=element_blank(), 
        axis.title=element_blank(),
        axis.line.x=element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        plot.title = element_text(size = 11, colour = "black", hjust= 0.5),
        plot.subtitle = element_text(size = 16, hjust = 1.1, face = "bold")
  ) + 
  labs(title="\n \n \n", subtitle = "Prior - Treatment") 

final <- arrangeGrob(K3, K1, K2, ncol = 3, widths=unit(c(190,350,350),"pt")) 
grid.arrange(K3, K1, K2, ncol = 3, widths=unit(c(180,350,350),"pt")) 


## exporting

pdf("Figure3.pdf", width = 18, height = 8) # Open a new pdf file
grid.arrange(K3, K1, K2, ncol = 3, widths=unit(c(180,350,350),"pt"))  # Write the grid.arrange in the file
dev.off() # Close the file



###Figure 4###


## Adding country variable

ttest_pro <- read.csv("ttest_combined_behavior_pro.csv")
ttest_contra <- read.csv("ttest_combined_behavior_contra.csv")


## Setting up auxiliary objects 

labels <- c("", "Neu   -   Neg", "Neg   -   Neg", "Pos   -   Neg", "Neu   -   Pos", "Neg   -   Pos", "Pos   -   Pos")
aux <- as.numeric(c(0:6))
aux_df <- as.data.frame(cbind(labels, as.numeric(aux)))


## Pro TTIP

K4 <- ggplot(ttest_pro, aes(color=factor(country), x = as.numeric(item), y = as.numeric(mean))) +
  #geom_pointrange(aes(ymin = ci_low, ymax = ci_up),position = position_dodge(width=.6)) + 
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) +  
  theme_bw() +
  ylim(c(-1, 1)) +
  coord_flip() + scale_colour_manual(name  ="Country",
                                     labels=c("GER", "USA"),
                                     values=c("black", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="Pro TTIP")


## Contra TTIP

K5 <- ggplot(ttest_contra, aes(color=factor(country), x = as.numeric(item), y = as.numeric(mean))) +
  #geom_pointrange(aes(ymin = ci_low, ymax = ci_up),position = position_dodge(width=.6)) + 
  geom_errorbar(aes(ymin = ci_low, ymax = ci_up), width = 0.2 , size=1.2) +  ## main geom object
  geom_point(size = 3) + 
  theme_bw() +
  ylim(c(-1, 1)) +
  coord_flip() + scale_colour_manual(name  ="Country",
                                     labels=c("GER", "USA"),
                                     values=c("black", "grey")) +
  theme(
    panel.grid.major=element_blank(), 
    panel.border=element_blank(), 
    axis.text.y=element_blank(), 
    axis.ticks.y=element_blank(), 
    axis.title=element_blank(), 
    axis.line.x=element_line(),
    legend.position="bottom",
    legend.title=element_blank(),
    plot.title = element_text(size = 16, face = "bold", colour = "black", hjust= .5),
    plot.subtitle = element_text(size = 11, face = "italic", hjust= .5),
    legend.text=element_text(size = 12),
    legend.key.width = unit(1, "cm"),
    panel.background = element_rect(fill = 'white', colour = 'white')) +
  geom_hline(yintercept = 0) +
  scale_x_continuous(breaks = c(0:6), labels = labels) +
  labs(title="Contra TTIP")


## Label 

K6 <- ggplot(data = aux_df, aes(1, aux)) + 
  geom_text(label = labels) + 
  ylim(0.03,6.05) +
  xlim(0.99, 1.01) +
  theme_bw() +
  theme(panel.grid.major=element_blank(),
        panel.grid.minor = element_blank(),
        panel.border=element_blank(), 
        axis.text.y=element_blank(), 
        axis.ticks.y=element_blank(), 
        axis.title=element_blank(),
        axis.line.x=element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        plot.title = element_text(size = 11, colour = "black", hjust= 0.5),
        plot.subtitle = element_text(size = 16, hjust = 1.1, face = "bold")
  ) + 
  labs(title="\n \n \n", subtitle = "Prior - Treatment") 

final <- arrangeGrob(K6, K4, K5, ncol = 3, widths=unit(c(190,350,350),"pt")) 
grid.arrange(K6, K4, K5, ncol = 3, widths=unit(c(180,350,350),"pt")) 


## exporting

pdf("Figure4.pdf", width = 18, height = 8) # Open a new pdf file
grid.arrange(K6, K4, K5, ncol = 3, widths=unit(c(180,350,350),"pt"))  # Write the grid.arrange in the file
dev.off() # Close the file



